﻿using System;
using System.Linq;
using System.Threading;
using System.Collections.Generic;

namespace iTunes.Scrubber
{
    class Program
    {
        static void Main(string[] args)
        {
            using (Factories.ScrubberFactory scrubberFactory = new Factories.ScrubberFactory())
            {
                if (true)
                {
                    Console.WriteLine("== Initializing iTunes DataSource ==");

                    DataSources.ITunesSource.Instance.Initialize();
                }
                
                if (true)
                {
                    Console.WriteLine("== Scrub TV Shows ==");

                    scrubberFactory.TVShowScrubber.Clean(
                        filter: Filters<MediaItems.TVShowItem>.Or(
                                Filters<MediaItems.TVShowItem>.CompleteMetaFilter(false),
                                Filters<MediaItems.TVShowItem>.TimeSpanFilter(new TimeSpan(1, 0, 0, 0))),
                        sorter: Sorters<MediaItems.TVShowItem>.ShowSorter
                    );
                }

                if (true)
                {
                    Console.WriteLine("== Remove Duplicate TV Shows==");

                    scrubberFactory.TVShowScrubber.RemoveDuplicates(
                        filter: Filters<MediaItems.TVShowItem>.CompleteMetaFilter(true),
                        sorter: Sorters<MediaItems.TVShowItem>.ShowSorter
                    );
                }

                if (true)
                {
                    Console.WriteLine("== List Missing Episodes ==");

                    scrubberFactory.TVShowScrubber.GetMissing(
                        sorter: Sorters<MediaItems.TVShowItem>.ShowSorter
                    ).ToList().ForEach(x => Console.WriteLine("{0} [{1:D2}x{2:D2}] {3}", x.Show, x.Season, x.Episode, x.Title));

                }

                if (true)
                {
                    Console.WriteLine("== List All Episodes In A Series ==");

                    DataSources.IMDBSource.Instance.GetEpisodes(
                        series: "Babylon 5",
                        sorter: Sorters<MediaItems.TVShowItem>.ShowSorter
                    ).ToList().ForEach(x => Console.WriteLine("{0} [{1:D2}x{2:D2}] {3}", x.Show, x.Season, x.Episode, x.Title));
                }

                if (false)
                {
                    Console.WriteLine("== Scrub Movies ==");

                    scrubberFactory.MovieScrubber.Clean();
                }

                if (false)
                {
                    Console.WriteLine("== Scrub Music Videos ==");

                    scrubberFactory.MusicVideoScrubber.Clean();
                }

                if (false)
                {
                    Console.WriteLine("== Scrub Music ==");

                    scrubberFactory.MusicScrubber.Clean();
                }

                Console.WriteLine("== Complete ==");
            }
        }
    }
}
